<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<title>Exported from Notepad++</title>
<style type="text/css">
span {
	font-family: 'Courier New';
	font-size: 10pt;
	color: #000000;
}
.sc0 {
}
.sc1 {
	font-style: italic;
	color: #0000FF;
}
.sc2 {
	font-style: italic;
	color: #0000FF;
}
.sc4 {
	color: #8000FF;
}
.sc5 {
	font-weight: bold;
	font-style: italic;
	color: #0000FF;
}
.sc6 {
	font-weight: bold;
	color: #008000;
}
.sc8 {
	font-weight: bold;
	font-style: italic;
	color: #008000;
}
.sc10 {
	font-weight: bold;
	color: #0080FF;
}
.sc11 {
}
.sc14 {
	color: #8080FF;
}
</style>
</head>
<body>
<div style="float: left; white-space: pre; line-height: 1; background: #FFFFFF; "><span class="sc2">// ========================================================= //</span><span class="sc0">
</span><span class="sc2">// ================ BIN2DEC.BPO : BEBOP 1.0 ================= //</span><span class="sc0">
</span><span class="sc2">// ========================================================= //</span><span class="sc0">

</span><span class="sc2">// compile with bopbuild</span><span class="sc0">

</span><span class="sc1">/**
 * BIN2DEC.BPO : binary to decimal with the bplib 
 * @author Mathieu Barbin &lt;barbin@clipper.ens.fr&gt;
*/</span><span class="sc0">

</span><span class="sc2">// Set the source language : (version 1.0 ocaml only)</span><span class="sc0">
</span><span class="sc2">// #source = "ocaml"</span><span class="sc0">

</span><span class="sc2">// Sys Arguments</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">intargv</span><span class="sc0">    </span><span class="sc8">AR</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc6">init</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">predAR</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">pred</span><span class="sc0"> </span><span class="sc11">_AR</span><span class="sc10">;;</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">tmp</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">Array</span><span class="sc10">.</span><span class="sc11">make</span><span class="sc0"> </span><span class="sc11">_AR</span><span class="sc0"> </span><span class="sc11">false</span><span class="sc10">;;</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">little_indian</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc6">not</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc8">List</span><span class="sc10">.</span><span class="sc11">mem</span><span class="sc0"> </span><span class="sc14">"-BI"</span><span class="sc0"> </span><span class="sc11">args</span><span class="sc10">);;</span><span class="sc0">

    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">print_LI</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0">
        </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">signed_d</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_signed_int</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0">
        </span><span class="sc6">and</span><span class="sc0"> </span><span class="sc11">d</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_int</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0">
        </span><span class="sc11">in</span><span class="sc0">
        </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"SIGNED   : %d\n"</span><span class="sc0"> </span><span class="sc11">signed_d</span><span class="sc10">;</span><span class="sc0">
        </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"UNSIGNED : %d\n"</span><span class="sc0"> </span><span class="sc11">d</span><span class="sc10">;</span><span class="sc0">
        </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc10">;;</span><span class="sc0">

    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">print_BI</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0">
        </span><span class="sc5">for</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc0"> </span><span class="sc5">to</span><span class="sc0"> </span><span class="sc11">predAR</span><span class="sc0"> </span><span class="sc5">do</span><span class="sc0">
            </span><span class="sc11">tmp</span><span class="sc10">.(</span><span class="sc11">i</span><span class="sc10">)</span><span class="sc0"> </span><span class="sc10">&lt;-</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc10">.(</span><span class="sc11">predAR</span><span class="sc0"> </span><span class="sc10">-</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc10">)</span><span class="sc0">
        </span><span class="sc11">done</span><span class="sc10">;</span><span class="sc0">
        </span><span class="sc11">print_LI</span><span class="sc0"> </span><span class="sc11">tmp</span><span class="sc10">;;</span><span class="sc0">

    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">print</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc0"> </span><span class="sc11">little_indian</span><span class="sc0"> </span><span class="sc5">then</span><span class="sc0"> </span><span class="sc11">print_LI</span><span class="sc0"> </span><span class="sc5">else</span><span class="sc0"> </span><span class="sc11">print_BI</span><span class="sc10">;;</span><span class="sc0">

    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">mode</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc0"> </span><span class="sc11">little_indian</span><span class="sc0"> </span><span class="sc5">then</span><span class="sc0"> </span><span class="sc14">"little indian"</span><span class="sc0"> </span><span class="sc5">else</span><span class="sc0"> </span><span class="sc14">"big indian"</span><span class="sc10">;;</span><span class="sc0">

    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">_</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0">
        </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"AR = %d, Mode = %s\n"</span><span class="sc0"> </span><span class="sc11">_AR</span><span class="sc0"> </span><span class="sc11">mode</span><span class="sc10">;</span><span class="sc0">
        </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc10">;;</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">

</span><span class="sc2">// Little Indian</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc6">method</span><span class="sc0"> </span><span class="sc8">LI</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">raw_a</span><span class="sc10">:[</span><span class="sc8">AR</span><span class="sc10">])</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">print_LI</span><span class="sc0"> </span><span class="sc11">raw_a</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">  

</span><span class="sc2">// Big Indian</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc6">method</span><span class="sc0"> </span><span class="sc8">BI</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc0"> </span><span class="sc11">raw_a</span><span class="sc10">:[</span><span class="sc8">AR</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">)</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">print_BI</span><span class="sc0"> </span><span class="sc11">raw_a</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc11">main</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">raw_a</span><span class="sc10">:[</span><span class="sc8">AR</span><span class="sc10">])</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">print</span><span class="sc0"> </span><span class="sc11">raw_a</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">
</span></div></body>
</html>
